package com.wanmait.myhouse.webController;

import com.alibaba.druid.stat.TableStat;
import com.wanmait.myhouse.dao.FeedBackDAO;
import com.wanmait.myhouse.vo.FeedBack;
import com.wanmait.myhouse.vo.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("web")
public class WebFeedbackResultsController {
    @GetMapping("feedBackResults")
    public String feedBackResults(FeedBack feedBack , Model model , Integer pno){
        FeedBackDAO feedBackDAO = new FeedBackDAO();
        Pager pager = new Pager();
        if (pno == null){
            pno = 1;
        }
        pager.setPageNO(pno);
        pager.setPageSize(4);
        int total =  feedBackDAO.getTotal(feedBack);
        int pageCount = total / pager.getPageSize()+(total% pager.getPageSize()==0?0:1);
        pager.setPageCount(pageCount);
        model.addAttribute("pager",pager);
        List<FeedBack> feedBackList = feedBackDAO.selectByUserId(feedBack.getUserId(),pager);
        model.addAttribute("feedBackList",feedBackList);
        return "web/FeedbackResults";
    }
}
